import { getAreaObj } from '@/utils/util'
import {BaseFormConfig} from './components/config'
const configToSearch = (colunm) =>{
	let list = []
	if(colunm){
		colunm.forEach(el => {
			if(el.type!='upload'){
				el.span = 24
				el.rules = []
				list.push(el)
			}
		})
	}
	return list
}
const tableConfig = {
	stripe: true,
	border: true,
	maxHeight: '80vh',
	columns: [
		{ label: '登记区域', prop: 'areas_name' },
		{ label: '机构名称', prop: 'organizationName' },
		{label:'评价分数',prop:''},
		{label:'异常行为',prop:''},
		{
			label: '统一社会信用代码',
			prop: 'creditCode',
		},
		{ label: '联系人', prop: 'burdenUserName' },
		{ label: '联系方式', prop: 'burdenUserPhone' },
		{
			label: '运营状态',
			prop: 'operateStatus',
			changeField: true,
			type: 'remoteSelect',
			code: 'ORG_OPERATE_STATUS',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
		},
		{
			label: '操作',
			prop: 'menu',
			fixed: 'right',
		},
	],
}

const searchConfig = {
	inline: true,
	showBtn: true,
	labelPosition: 'left',
	column: [
		{
			label: '信用代码',
			prop: 'creditCode',
			type: 'input',
			span: 8,
		},
		{
			label: '机构名称',
			prop: 'organizationName',
			type: 'input',
			span: 8,
		},
		{
			label: '联系人',
			prop: 'burdenUserName',
			type: 'input',
			span: 8,
		},
		{
			label: '所属地区',
			prop: 'areas',
			type: 'AplidAreaSelect',
			span: 8,
		},
		{
			label: '联系方式',
			prop: 'burdenUserPhone',
			type: 'input',
			span: 8,
		},
		{
			label: '运营状态',
			prop: 'operateStatus',
			changeField: true,
			type: 'remoteSelect',
			code: 'ORG_OPERATE_STATUS',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 8,
		},
	],
}
export const baseConfig = {
	pageName: '养老服务组织管理',
	dictcodes: [
		'COMMON_FLAG',
		'ORG_TYPE',
		'ORG_LEVEL',
		'ORG_OPERATE_STATUS',
		'ID_CARD_TYPE',
		'LEGAL_PROPERTY',
		'MEDICAL_MODE',
		'MEDICAL_INSTITUTE',
		'MEDICAL_COOPERATE_TYPE',
		'MEDICAL_INSURE_NETWORK_MODE',
		'MEDICAL_INSURE_LEVEL',
		'SERVICE_ITEM_TYPE',
		'NURSE_LEVEL',
		'OLDMAN_TYPE',
		'LAND_PROPERTY',
		'HOUSE_PROPERTY',
		'HOUSE_PROVE_STATUS',
		'OLDMAN_PRODUCT_TYPE',
		'DEVICE_TYPE',
		'FIRE_APPROVAL_STATUS',
		'PREVENT_DEPOSIT',
		'SUBSIDY_TYPE'
	],
	rowKey: 'id',
	addLabel: '采集数据',
	tipLabel: 'organizationName',
	// needPigeonhole:true, // 是否显示顶部关于归档的部分
	exportMqTopic: [
		{
			topic: '/ning/export/dpServiceOrgBasePO/',
			label: '基础数据',
			code: 3013,
			po: 'dpServiceOrgBasePO',
		},
		{
			topic: '/ning/export/dpServiceOrgDevicePO/',
			label: '设施设备',
			code: 3014,
			po: 'dpServiceOrgDevicePO',
		},
		{
			topic: '/ning/export/dpServiceOrgExtendPO/',
			label: '扩展信息',
			code: 3015,
			po: 'dpServiceOrgExtendPO',
		},
		{
			topic: '/ning/export/dpServiceOrgItemsPO/',
			label: '服务项目',
			code: 3016,
			po: 'dpServiceOrgItemsPO',
		},
		{
			topic: '/ning/export/dpServiceOrgOtherPO/',
			label: '其他信息',
			code: 3017,
			po: 'dpServiceOrgOtherPO',
		},
		{
			topic: '/ning/export/dpServiceOrgProductPO/',
			label: '老年用品',
			code: 3018,
			po: 'dpServiceOrgProductPO',
		},
	],
	api: {
		index: 'view_dpServiceOrgBase_page',
		delete: 'view_dpServiceOrgBase_del',
		export: 'view_dpServiceOrgBase_exportAll',
	},
	auth: {
		index: 'view_dpServiceOrgBase_page',
		delete: 'view_dpServiceOrgBase_del',
		mulitSet: 'mulitSet',
		export: 'view_dpServiceOrgBase_exportAll',
	},
	menuBtn: [
		{
			icon: 'editor',
			label: '查看档案',
			type: 'primary',
			operate: 'Archives',
			auth: 'sys_role_edit',
			text: true,
			show: true,
		},
	],
	dialogConfig: {
		width: '90%',
		// fullscreen: true
	},
	moreSearchConfig: {
		inline: true,
		showBtn: false,
		labelPosition: 'left',
		column: [
			...configToSearch(BaseFormConfig.column),
		],
		},
	detailConfig: {
		customeHeader: {
			type: 'CardOne',
			title: 'organizationName',
			avatar: 'organizationLogo',
			tipList: [{ prop: 'operateStatusLabel', type: 'tip-success', label: '运营状态' }],
			tagList: [{ prop: 'organizationTypeLabel', custome: 'tag', type: 'success', label: '机构类型' }],
			menuBtn: [
				{
					icon: 'delete',
					label: '删除服务组织',
					type: 'danger',
					operate: 'delete',
					auth: 'view_dpServiceOrgBase_del',
					text: false,
					show: true,
					plain: true,
				},
			],
		},
	},
	searchConfig,
	beforeOnLoadFormate: async (params) => {
		const areasObj: any = getAreaObj(params.areas, '')
		return Promise.resolve({
			...params,
			...areasObj,
			areas: undefined,
		})
	},
	onLoadFormate: async (arr) => {
		const tableData = arr.map((item) => {
			const areasObj: any = getAreaObj(item, '', 'set')
			const nowAreaObj: any = getAreaObj(item, 'now', 'set')
			return {
				...item,
				areas_name: areasObj.names,
				nowAreasNames: nowAreaObj.names,
			}
		})
		return Promise.resolve(Object.freeze(tableData))
	},
	tableConfig,
}
